import { Component,OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {HttpURLService} from "../../httpURL.service";

/**
 * 接收日志服务
 * guopeng
 * 2017.11.27
 */
export class ReceiveLog{
  constructor(
    private id : string,//主键id
    private clientIp : string,//客户端Ip
    private mn : string,//设备唯一标识
    private qn : string,//请求编码
    private cn :string,//命令编码
    private message : string,//指令信息
    private createTime : string,//创建时间
    private datatime : string,//接收时间
    private extensionInfo : string,//拓展信息
    private startTime : string,//开始时间
    private endTime :string//结束时间
  ){}
}

@Component({
  selector: 'app-receiveLog',
  templateUrl: './receiveLog.component.html',
  styleUrls: ['./receiveLog.component.css']
})
export class ReceiveLogComponent implements OnInit{
  private mn : string;//设备唯一标识
  private cn :string;//命令编码
  private startTime : string;//开始时间
  private endTime :string;//结束时间
  private list:Array<any>;
  public queryMessage:ReceiveLog = new ReceiveLog("","","","","","","","","","","");
  public params; // 保存页面url参数
  public pageSize:any = 5;// 每页数据条数
  public curPage:any = 1;// 当前页码
  public totalNum: any = 0; // 总数据条数
  public totalPage: any = 0;// 总页数
  public url:string = this.httpURLService.getUrl("communication");
  constructor(private http: HttpClient,private httpURLService: HttpURLService) {
  }
  userMessage(event:any){
    let query = new ReceiveLog("","","","","","","","","","","");
    Object.assign(query, event);
    this.queryMessage = query;
  }
  listMessage(info:any){
    let mn = info.mn== undefined ? '' : info.mn ;
    let cn = info.cn== undefined ? '' : info.cn;
    let startTime = $("#startTime").val()== undefined ? '' : $("#startTime").val();
    let endTime = $("#endTime").val()== undefined ? '' : $("#endTime").val();
    this.http.get(this.url+'/log/queryReceiveLogListByPage?mn='+mn+'&cn='+cn+'&startTime='+startTime+'&endTime='+endTime).subscribe(data => {
      this.totalNum = data['total'];
      this.totalPage = data['pages'];
      this.curPage = data['current'];
      this.pageSize = data['size'];
      this.list  = data['records'];
    })
  }
  getPageData(pageNo) {
    let vm = this;
    vm.curPage = pageNo;
    let mn = this.mn== undefined ? '' : this.mn ;
    let cn = this.cn== undefined ? '' : this.cn;
    let startTime = this.startTime== undefined ? '' : this.startTime;
    let endTime = this.endTime== undefined ? '' : this.endTime;
    let current = pageNo;
    this.http.get(this.url+'/log/queryReceiveLogListByPage?mn='+mn+'&cn='+cn+'&startTime='+startTime+'&endTime='+endTime+'&current='+current).subscribe(data => {
      this.totalNum = data['total'];
      this.totalPage = data['pages'];
      this.curPage = data['current'];
      this.pageSize = data['size'];
      this.list  = data['records'];
    })
  }

	onstructor(){ }
	ngOnInit(){
    this.dateRangePicker();
    this.endTimePicker();
    this.http.get(this.url+'/log/queryReceiveLogListByPage').subscribe(data => {
      this.totalNum = data['total'];
      this.totalPage = data['pages'];
      this.curPage = data['current'];
      this.pageSize = data['size'];
      this.list  = data['records'];
    });
	}
  endTimePicker(){
    let picker:any=$('#endTime');
    let dataRageOption:Object={
      "singleDatePicker":true,
      "timePicker": true,
      "timePicker24Hour": true,
      "locale": {
        "format": "YYYY-MM-DD HH:mm:ss",
        "applyLabel": "确定",
        "cancelLabel": "取消",
        "customRangeLabel": "Custom",
        "daysOfWeek": ["日","一","二","三","四","五","六"],
        "monthNames": ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
      }
    };
    picker.daterangepicker(dataRageOption,function (start,end,label) {
      this.startTime = start.format('YYYY-MM-DD HH:mm:ss');
      console.log(`start:${start.format('YYYY-MM-DD HH:mm:ss')}, end:${end}, label:${label}`);
    });
  }
  dateRangePicker(){
    let picker:any=$('#startTime');
    let dataRageOption:Object={
      "singleDatePicker":true,
      "timePicker": true,
      "timePicker24Hour": true,
      "locale": {
        "format": "YYYY-MM-DD HH:mm:ss",
        "applyLabel": "确定",
        "cancelLabel": "取消",
        "customRangeLabel": "Custom",
        "daysOfWeek": ["日","一","二","三","四","五","六"],
        "monthNames": ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
      }
    };
    picker.daterangepicker(dataRageOption,function (start,end,label) {
      console.log(`start:${start.format('YYYY-MM-DD HH:mm:ss')}, end:${end}, label:${label}`);
    });
  }
}


